package com.zhai.domain.strategy.repository;

import com.zhai.domain.strategy.model.entity.StrategyAwardEntity;
import com.zhai.domain.strategy.model.entity.StrategyEntity;
import com.zhai.domain.strategy.model.entity.StrategyRuleEntity;
import com.zhai.domain.strategy.model.valobj.RuleTreeVO;
import com.zhai.domain.strategy.model.valobj.RuleWeightVO;
import com.zhai.domain.strategy.model.valobj.StrategyAwardRuleModelVO;
import com.zhai.domain.strategy.model.valobj.StrategyAwardStockKeyVO;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 策略仓储接口
 * @ClassName: IStrategyRepository
 * @Author: zhaiyongxin
 * @Date: 2024/12/31 11:08
 * @Version: 1.0
 */
public interface IStrategyRepository {


    List<StrategyAwardEntity> queryStrategyAwardList(Long strategyId);

    void storeStrategyAwardSearchRateTables(String cacheKey, Integer rateRange, HashMap<Integer, Integer> shuffledStrategyAwardSearchRateTable);

    int getRateRange(String key);

    Integer getStrategyAwardAssemble(String key, int rateKey);

    StrategyEntity queryStrategyEntityByStrategyId(Long strategyId);

    StrategyRuleEntity queryStrategyRule(Long strategyId, String ruleModel);

    String queryStrategyRuleValue(Long strategyId, Integer awardId, String ruleModel);
    String queryStrategyRuleValue(Long strategyId, String ruleModel);

    StrategyAwardRuleModelVO queryStrategyAwardRuleModelVO(Long strategyId, Integer awardId);

    RuleTreeVO queryRuleTreeVOByTreeId(String treeLock);

    void cacheStrategyAwardCount(String cacheKey, Integer awardCount);

    /**
     * 扣减库存
     * @param cacheKey
     * @return
     */
    Boolean subtractionAwardStock(String cacheKey, Date endDateTime);

    /**
     * 写入库存更新延迟队列
     * @param build
     */
    void awardStockConsumeSendQueue(StrategyAwardStockKeyVO strategyAwardStockKeyVO);

    /**
     * 获取奖品库存消费队列
     */
    StrategyAwardStockKeyVO takeQueueValue();

    void updateStrategyAwardStock(Long strategyId, Integer awardId);

    /**
     * 查询奖品信息
     * @param strategyId
     * @param awardId
     * @return
     */
    StrategyAwardEntity queryStrategyAwardEntity(Long strategyId, Integer awardId);

    Long queryStrategyIdByActivityId(Long activityId);

    /**
     * 查询当天总次数
     * @param userId
     * @param strategyId
     * @return
     */
    Integer queryTodayUserRaffleCount(String userId, Long strategyId);

    /**
     * 查询规则树次数锁规则
     * @param treeIds
     * @return
     */
    Map<String, Integer> queryAwardRuleLockCount(String[] treeIds);

    List<RuleWeightVO> queryAwardRuleWeight(Long strategyId);

    /**
     * 获取算法缓存bean名称
     * @param key
     * @return
     */
    String queryStrategyArmoryAlgorithmFromCache(String key);

    /**
     * 缓存bean名称
     * @param key
     * @param key1
     */
    void cacheStrategyArmoryAlgorithm(String key, String key1);
}
